#include "CFolderUploadLib.h"
#include <iostream>
#include <chrono>
#include <thread>
#include <windows.h>

uint64_t startTs = 0;

void printProgress(UpStatInfo progress) {
    std::cout << "\rfail_count: " << progress.fail_count 
        << " total_count:" <<progress.total_count 
        <<" time: " << (GetTickCount64() - startTs) 
        << std::endl;
        //<< std::flush;    
}

void uploadComplete(bool success, const std::string& message) {
    std::cout << "\n上传完成: " << message << std::endl;
}

int main() {

    SetConsoleOutputCP(CP_UTF8);

    CFolderUploadLib* obj = CreateLibObject(0);
    
    // 设置回调函数
    obj->setProgressCallback(printProgress);
    obj->setCompleteCallback(uploadComplete);
    
    // 设置上传参数（替换为实际的文件夹路径和上传URL）
    FolderUploadParam conf;
    conf.local_root_path = u8"D:/detect_server_work_path/short_burst";
    conf.file_service_url = "http://127.0.0.1:4000/api/file";
    conf.delete_after_upload = false;
    conf.file_suffix_upload = "dat";
    conf.thread_count = 4;
    
    obj->setUploadParams(conf);
    
    // 开始上传
    std::cout << "开始上传文件夹: " << conf.local_root_path << std::endl;
    obj->startUpload();
    startTs = GetTickCount64();
    
    std::string cmd;
    while (std::getline(std::cin, cmd))
    {
        if ("stop" == cmd)
        {
            obj->stopUpload();
            break;
        }        
    }
    
    DestorytLibObject(obj);
    std::cout << "程序结束" << std::endl;
    return 0;
}
